package org.example.spring.controller.User;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.spring.domain.dto.OrderDetailDTO;
import org.example.spring.domain.pojo.OrderDetail;
import org.example.spring.domain.pojo.Result;
import org.example.spring.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@Api(tags = "购物车详情相关接口")
@RestController("userOrderDetailController")
@RequestMapping("/user/orderDetail")
public class OrderDetailController {

    @Autowired
    private OrderDetailService orderDetailService;

    @ApiOperation("添加订单详情")
    @PostMapping("/addOrderDetail")
    public Result addOrderDetail(@RequestBody Map<String, ArrayList<OrderDetail>> orderDetailMap) {
        ArrayList<OrderDetail> orderDetailList = orderDetailMap.get("orderDetailList");
        orderDetailService.addOrderDetail(orderDetailList);
        return Result.success("添加成功");
    }

    @ApiOperation(value = "根据订单号获取订单详情")
    @RequestMapping("/getOrderDetailByOrderId")
    public Result<ArrayList<OrderDetailDTO>> getOrderDetailByOrderId(@RequestParam Integer orderId) {
        ArrayList<OrderDetailDTO> orderDetails = orderDetailService.getOrderDetailByOrderId(orderId);
        return Result.success(orderDetails);
    }


}
